<?php

/**
 * Replace dirname(__FILE__) by __DIR__
 */
define('ROOT_DIR', dirname(__FILE__));
define('CODE_DIR', ROOT_DIR . '/code');

$paths = array(
        get_include_path(),
        ROOT_DIR . '/lib'
);

error_reporting(E_ALL ^ E_NOTICE);

set_include_path(implode(PATH_SEPARATOR, $paths));

require 'Fete/Loader.php';
Fete_Loader::registerAutoload();

require 'configs/db.php';
require 'configs/php.php';

/**
 * @return Fete_Db
 */
function db()
{
    static $db = null;
    if (null === $db) {
        $db = new Fete_Db(DB_HOST, DB_USER, DB_PASS, DB_NAME);
        $db->setConnectionEncoding('utf8')->enableAutoReconnection(true);
        return $db;
    }
    return $db;
}

/**
 * @return Fete_Logger
 */
function logger()
{
    static $logger = null;
    if (null === $logger) {
        $logger = new Fete_Logger(ROOT_DIR . '/logs');
    }

    return $logger;
}

/**
 * @return Fete_Cache
 */
function cacher()
{
    $cacher = null;
    if (null === $cacher) {
        $cacher = Fete_Cache::getInstance(ROOT_DIR . '/caches');
    }

    return $cacher;
}

function baseUrl()
{
    return Fete_Kernel::getInstance()->getBaseUrl();
}

Fete_Language::getInstance()->loadFile(ROOT_DIR . '/languages/' . Lang::getCode() . '.php');

Fete_Front::getInstance()->setActionDir(ROOT_DIR . '/code')
        ->setViewDir(ROOT_DIR . '/tpl')
        ->run();

?>
